import { Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FieldSchemaSection, ObjectFieldSchemaSection } from '../json-schema';
import { FormItem, getControls } from '../getControls';

@Component({
  selector: 'property-group',
  templateUrl: './property-group.component.html',
  styleUrl: './property-group.component.scss'
})
export class PropertyGroupComponent {
  @Input() group!: FormGroup;
  @Input() groupName?: string;
  @Input() schema!: ObjectFieldSchemaSection;

  get controls(): FormItem[] {
    return getControls(this.group);
  }

  propertySchema(key: string): FieldSchemaSection | undefined {
    try {
      return this.schema.properties?.[key];
    } catch (error) {
      console.log(error);
      return;
    }

  }
}
